package mspbots.cw.business.core.agreements;

import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import reactor.core.publisher.Mono;

/**
 * @author Jay.Yang
 */
public interface AgreementsRepository extends R2dbcRepository<Agreements, Long> {

    /**
     * find entity other id and tenant id
     *
     * @param cwId       cwId
     * @param tenantCode tenantCode
     * @return account entity
     */
    Mono<Agreements> findByCwIdAndTenantCode(Long cwId, Long tenantCode);

    /**
     * count query cancelled flag false and Agreement Status
     *
     * @param tenantCode tenant code
     * @param companyId  company id
     * @param status     Agreement Status
     * @return count result
     */
    @Query("select count(*) from connectwise_agreements where " +
            "tenant_code=:tenantCode and company_id =:companyId and cancelled_flag=false and Agreement_Status=:status  ")
    Mono<Integer> countFlagStatus(Long tenantCode, Long companyId, String status);
}
